package com.example.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@ComponentScan(basePackages = {"com.example"})
@PropertySource("classpath:jdbc.properties")
public class ApplicationConfig {
    //@Bean("dataSource")
    //public DruidDataSource getDruidDataSource(){
    //    DruidDataSource dataSource = new DruidDataSource();
    //    dataSource.setDriverClassName("1");
    //    dataSource.setUrl("2");
    //    dataSource.setUsername("3");
    //    dataSource.setPassword("4");
    //    return dataSource;
    //}

    @Value("${mysql.driverClassName}")
    private String driverClassName;
    @Value("${mysql.url}")
    private String url;
    @Value("${mysql.username}")
    private String username;
    @Value("${mysql.password}")
    private String password;
    @Bean
    public DruidDataSource getDruidDataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
